define(["components"],function(){
  
  function Layer(name){
    this.name=name;
    this.components=new Array();
  }
  
  /**
   * 是否可见.
   */
  Layer.prototype.visible=true;
  
  Layer.prototype.components=undefined;
  
  Layer.prototype.addComp=function(comp){
    this.components.push(comp);
    
    if(comp.name){
      this.components[comp.name]=comp;
    }
    
  };
  
  Layer.prototype.clear=function(){
    this.components.length=0;
  }
  
  Layer.prototype.removeComp=function(comp){
    if(comp){
      var tmp = [];
      $(this.components).each(
        function(){
          if(this!=comp){
            tmp.push(this);
            if(this.name){
              tmp[this.name]=this;
            }
          }
        }
      );
      this.components=tmp;
    }
  };
  
  Layer.prototype.removeCompByName=function(name){
    if(!isBlank(name)){
      console.log(name)
      return this.removeComp(this.components[name]);
    }
  }
  
  
  Layer.prototype.render=function(target,ctx2d,logicWidth,logicHeight,domWidth,domHeight){
    
    this.visible&&$(this.components).each(
      function(){
        if(this&&this.render&&typeof this.render=='function'){
          this.render(target,ctx2d,logicWidth,logicHeight,domWidth,domHeight);
        }
      }
    );
  };
  
  window.Layer=Layer;
  return Layer;
  
});